//
//  ViewController.m
//  09-UITableVieController
//
//  Created by GivenBmli on 16/7/26.
//  Copyright © 2016年 GivenBmli. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()
@property (nonatomic , strong)NSMutableArray *nameArray;

@end
#define  kTableViewCellReuse @"reuse"
@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    NSArray *arry = @[@"唐益梦", @"张合尉", @"高雅馨", @"符淋淋", @"孙遥", @"李毅然", @"于瀚", @"沙长健", @"卢思彤", @"徐昊", @"曹冠雄", @"陈丹明", @"罗浩", @"肖扬", @"王道林", @"宫雪", @"李成", @"冀永金", @"姜浩", @"罗鹏飞", @"李昊林", @"郭宝", @"马峰", @"刘坦奇", @"殷明静", @"邓凯", @"徐康", @"王鍠", @"韩旭", @"杨睿", @"张信宝", @"姜程程", @"包铭礼", @"杜江", @"苗钧豪"];
    self.nameArray = [NSMutableArray arrayWithArray:arry];
    [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:kTableViewCellReuse];
    
//    UIView *view1 = [[UIView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 200)];
//    view1.backgroundColor = [UIColor redColor];
//    [self.view addSubview:view1];
//    注意: UItableViewController 中self.view 是tableView
    NSLog(@"%@",self.view);
    NSLog(@"%@",self.refreshControl);
//  1.系统刷新UIRefreshControl
//    注意:UIRefreshControl 有子级init 方法
//    默认:大小, 屏幕宽 高60
    self.refreshControl = [[UIRefreshControl alloc]init];
//    2.UIRefreshControl继承UIcontrol
//    可以绑定时间
//    系统API注释中说明触发枚举值,UIControlEventValueChanged
    [self.refreshControl addTarget:self action:@selector(refreshAction:) forControlEvents:UIControlEventValueChanged];
    
}
//刷新的方法
- (void)refreshAction:(UIRefreshControl *)refreshControl {
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
//        刷新控件结束刷新
        [self.refreshControl endRefreshing];
    });
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return _nameArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:kTableViewCellReuse];
    cell.textLabel.text = _nameArray[indexPath.row];
    return cell;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
